home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / msqc25t1 / textscrn.c < prev    next >
C/C++ Source or Header  |  1990-09-26  |  9KB  |  237 lines

  1. /* textscrn.c: Stretching text screen operations for QC 2.0 */
  2. /* Library source
  3.  
  4.     This program must be compiled in large model.
  5. */
  6.  
  7. #include <graph.h>
  8. #include <dos.h>
  9. #include <string.h>
  10. #include <stdarg.h>
  11. #include <malloc.h>
  12. #include <stdio.h>
  13. #include "biosarea.h"
  14. #include "mk_fp.h"
  15. #include "textscrn.h"
  16.  
  17. #if !defined TRUE
  18. #define FALSE 0
  19. #define TRUE !FALSE
  20. #endif
  21.  
  22. typedef struct scrnimage {
  23.     unsigned char   dispmem [4000];
  24.     struct scrnimage far *prev;
  25.     struct rccoord  textpos;
  26.     short           fgcolor, bgcolor;
  27. } SCRNIMAGE;
  28.  
  29. BIOSDATA far *bios = MK_FP (0x40, 0);   /* ROM BIOS data area */
  30. struct videoconfig video;               /* video configuration */
  31. int init_done = FALSE;                  /* if initialized */
  32. SCRNIMAGE far *scrnstack = NULL;    /* screen image stack pointer */
  33.  
  34. /*-------------------------------------------------------------------------*/
  35. /*                           LOCAL ROUTINE                                 */
  36. /*-------------------------------------------------------------------------*/
  37. void near initialize (void)             /* initalize for these fcns */
  38. {
  39.     _getvideoconfig (&video);           /* get video info */
  40.     init_done = TRUE;                   /* set switch */
  41. }
  42.  
  43. /*-------------------------------------------------------------------------*/
  44. /*                        CONTROL FUNCTIONS                                */
  45. /*-------------------------------------------------------------------------*/
  46. void far _outtextf (char *ps, ...)      /* Formatted output */
  47. {                                       /* Pass arg as for printf() */
  48.     char fline [80];
  49.     va_list ap;
  50.  
  51.     va_start (ap, ps);
  52.     vsprintf (fline, ps, ap);           /* format string */
  53.     va_end (ap);
  54.     _outtext (fline);                   /* write to video memory */
  55. } /*-------------------------------*/
  56.  
  57. void far _outch (char ch)               /* Single char output */
  58. {
  59.     char str [2];
  60.  
  61.     str [0] = ch;                       /* make a short string */
  62.     str [1] = '\0';
  63.     _outtext (str);                     /* and output it */
  64. } /*-------------------------------*/
  65.  
  66. void far _cleareol (void)               /* clear to end of line from */
  67. {                                       /* current cursor position */
  68.     register    c;
  69.     char        blank [81];
  70.     struct rccoord text;
  71.  
  72.     if (!init_done) initialize();       /* be sure we're set up */
  73.     for (c = 0; c < 80; c++) blank [c] = ' ';   /* clear blank */
  74.     text = _gettextposition();          /* where are we? */
  75.     c = video.numtextcols - text.col;   /* how far to right edge? */
  76.     blank [c+1] = '\0';                 /* make blank that long */
  77.     _outtext (blank);                   /* write spaces */
  78.     _settextposition (text.row, text.col);  /* restore cursor */
  79. } /*-------------------------------*/
  80.  
  81. void far _textbox (int top, int left,
  82.                     int bott, int rite, int style)
  83.                         /* Draw box in text mode    */
  84.                         /* Style arguments:         */
  85.                         /*      0 = no box          */
  86.                         /*      1 = single-scored   */
  87.                         /*      2 = double-scored   */
  88. {
  89.     register r, c;
  90.     char    horiz [81];
  91.     static  bord [][6] = {          /* border characters */
  92.         { 196, 179, 218, 191, 217, 192 },
  93.         { 205, 186, 201, 187, 188, 200 }
  94.     };
  95.  
  96.     if (style == 0 ) return;        /* no action, else... */
  97.  
  98.     /* Initialize */
  99.     for (c = 0; c < 81; c++) horiz[c] = '\0';   /* horiz string */
  100.         --style;                                /* index to border set */
  101.  
  102.     /* Make sure coords are in proper oder */
  103.     if (left > rite) c = left, left = rite, rite = c;
  104.     if (top > bott)  c = top, top = bott, bott = c;
  105.  
  106.     /* Draw top */
  107.     for (c=1; c<rite-left; c++)
  108.         horiz[c] = bord [style][0];             /* horiz char */
  109.     horiz[c] = bord [style][3];                 /* top right corner */
  110.     horiz[0] = bord [style][2];                 /* top left corner */
  111.     _settextposition (top,left);
  112.     _outtext (horiz);                           /* draw it */
  113.  
  114.     /* Draw bottom */
  115.     horiz[c] = bord [style][4];                 /* bottom right corner */
  116.     horiz[0] = bord [style][5];                 /* bottom left corner */
  117.     _settextposition (bott,left);
  118.     _outtext (horiz);                           /* draw it */
  119.  
  120.  
  121.  
  122.     /* Draw sides */
  123.     for (r = top+1; r < bott; r++) {
  124.         _settextposition (r, left);             /* left side */
  125.         _outch (bord [style][1]);               /* vertical char */
  126.         _settextposition (r, rite);             /* right side */
  127.         _outch (bord [style][1]);               /* vertical char */
  128.     }
  129. } /*-------------------------------*/
  130.  
  131. void far _savescrn (int page )                  /* save screen image */
  132.                                                 /* pushes image onto a stack */
  133. {
  134.     SCRNIMAGE far *new;
  135.     unsigned char far *vidmem;
  136.     short oldpage;
  137.  
  138.     oldpage = _setactivepage (page);        /* remember where we are */
  139.     new = _fmalloc (sizeof (SCRNIMAGE));        /* get space */
  140.     new->prev = scrnstack;                  /* point to previous image */
  141.     scrnstack = new;                        /* update stack pointer */
  142.     new->textpos = _gettextposition();      /* save cursor position */
  143.     new->fgcolor = _gettextcolor();         /* save current colors */
  144.     new->bgcolor = _getbkcolor();
  145.     vidmem = (bios->videoMode == 7)         /* video memory addr */
  146.         ? MK_FP (0xB000, (page * 0x1000))
  147.         : MK_FP (0xB800, (page * 0x1000));
  148.     movedata (FP_SEG (vidmem), FP_OFF (vidmem),     /* save image */
  149.                 FP_SEG (new), FP_OFF (new), 4000);
  150.     _setactivepage (oldpage);           /* return to active page */
  151. } /*-------------------------------*/
  152.  
  153. void far _restscrn (int page )                  /* restore screen image */
  154.                                                 /* pops image off a stack */
  155. {
  156.     unsigned char far *vidmem;
  157.     SCRNIMAGE far *top;
  158.     short oldpage;
  159.  
  160.     if (scrnstack) {                        /* proceed if stack not empty */
  161.         _settextwindow (1, 1, 25, 80);
  162.         oldpage = _setactivepage (page);        /* remember where we are */
  163.         top = scrnstack;                        /* top of stack */
  164.         vidmem = (bios->videoMode == 7)         /* video memory addr */
  165.             ? MK_FP (0xB000, (page * 0x1000))
  166.             : MK_FP (0xB800, (page * 0x1000));
  167.         movedata (FP_SEG (top), FP_OFF (top),     /* save image */
  168.                     FP_SEG (vidmem), FP_OFF (vidmem), 4000);
  169.         _settextcolor (top->fgcolor);           /* restore colors */
  170.         _setbkcolor ((long)(top->bgcolor));
  171.         _settextposition                        /* restore cursor position */
  172.                 (top->textpos.row, top->textpos.col);
  173.         if(oldpage != page)
  174.             _setactivepage (oldpage);           /* return to active page */
  175.         scrnstack = top->prev;                  /* update stack pointer */
  176.         _ffree (top);                           /* free space */
  177.     }
  178. } /*-------------------------------*/
  179.  
  180. void far _setbordwindow (int top, int left,         /* bordered window */
  181.                             int bott, int rite,
  182.                             int style, int fgcolor, int bgcolor)
  183. {
  184.     int c;
  185.  
  186.     /* Make sure coords are in proper oder */
  187.     if (left > rite) c = left, left = rite, rite = c;
  188.     if (top > bott)  c = top, top = bott, bott = c;
  189.  
  190.     /* Construct border window */
  191.     _settextwindow (1, 1, 25, 80);                  /* use full screen */
  192.     _settextcolor (fgcolor);                        /* set colors */
  193.     _setbkcolor ((long)(bgcolor));
  194.     _textbox (top-1, left-1, bott+1, rite+1, style);    /* border */
  195.     _settextwindow (top, left, bott, rite);         /* open window */
  196.     _clearscreen (_GWINDOW);                        /* clear window */
  197. } /*-------------------------------*/
  198.  
  199. /*-------------------------------------------------------------------------*/
  200. /*                   INQUIRY FUNCTIONS                                     */
  201. /*-------------------------------------------------------------------------*/
  202.  
  203. int far maxcol (void)                           /* max column on display */
  204. {
  205.     if (!init_done) initialize();
  206.     return video.numtextcols;
  207. } /*-------------------------------*/
  208.  
  209. int far maxrow (void)                           /* max row on display */
  210. {
  211.     if (!init_done) initialize();
  212.     return video.numtextrows;
  213. } /*-------------------------------*/
  214.  
  215. int far maxpage (void)                           /* highest avail video page */
  216. {
  217.     if (!init_done) initialize();
  218.     return video.numvideopages;
  219. } /*-------------------------------*/
  220.  
  221. int far wherex (void)                           /* cursor col in active page */
  222. {
  223.     struct rccoord text;
  224.  
  225.     text = _gettextposition();
  226.     return text.col;
  227. } /*-------------------------------*/
  228.  
  229. int far wherey (void)                           /* cursor row in active page */
  230. {
  231.     struct rccoord text;
  232.  
  233.     text = _gettextposition();
  234.     return text.row;
  235. } /*-------------------------------*/
  236.  
  237.